#pragma once

#include "layoutDesc.h"

/// Helper class to build the layout
class CLayoutBuilder
{
public:
	/// Error reporter
	class IErrorReporter
	{
	public:
		virtual ~IErrorReporter() {};
		virtual void EmitError( const char* message ) = 0;
	};

	CLayoutBuilder( IErrorReporter& errorReporter, CLayoutDefinition* def );

	/// Start group declaration, returns false on error
	CLayoutGroup* AddGroup( const std::string& name, const bool isMessage );

	/// Set base group
	void SetBaseGroup( CLayoutGroup* group, const std::string& baseGroupName );

	/// Add group element
	CLayoutGroupElement* AddField( CLayoutGroup* group, const std::string& name, const std::string& type, bool isOptional, bool isArray );

	/// Set attribute default value
	void SetDefaultValue( CLayoutGroupElement* elem, const std::string& defaultValue );

	/// Set group var type
	bool SetGroupValueType( CLayoutGroup* group, const std::string& type );

private:
	// definition file being built
	CLayoutDefinition*		m_definition;

	// error context
	std::string				m_file;
	int						m_line;

	// external error reporter
	IErrorReporter*			m_errorReporter;		

	// parse type name
	static bool ParseType( const std::string& name, ELayoutVarType& outVarType );

	// error reporter
	void EmitError( const char* message, ... );
};